<template>
  <div class="table-page-search-wrapper">
    <a-card>
      <a-form layout="vertical">
        <a-row :gutter="48">
          <a-col :md="6" :sm="12">
            <a-form-item
                label="学号"
            >
              <a-input v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="12">
            <a-form-item
                label="姓名"
            >
              <a-input v-model="queryParam.xm"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="12">
              <a-form-item label="院系">
                <a-select allowClear v-model="queryParam.ssyxm" @change="yxChange" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.yxList" :key="i.id" :value="i.dwh">{{ i.dwh }} {{ i.dwmc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>

          <template v-if="advanced">
            <a-col :md="6" :sm="12">
              <a-form-item label="专业">
                <a-select allowClear v-model="queryParam.sszym" showSearch :filterOption="filterOption">
                  <a-select-option v-for="i in selectMenu.zyList" :key="i.id" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item
                label="论文题目"
              >
                <a-input v-model="queryParam.lwtm"/>
              </a-form-item>
            </a-col>
            <a-col :md="6" :sm="12">
              <a-form-item
                label="授予学位的大学"
              >
                <a-input v-model="queryParam.syxwddx"/>
              </a-form-item>
            </a-col>

          </template>
          <a-col :md="12" :sm="12">
            <span class="table-page-search-submitButtons" >
              <a-button type="primary" @click="$refs.table.refresh(true)" style="margin:0 8px">查询</a-button>
              <a-button type="primary" @click="exportExcel">导出</a-button>
              <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <a-card :bordered="false" style="margin-top: 10px">
      <s-table
        ref="table"
        size="default"
        rowKey="id"
        :columns="columns"
        :data="loadData"
        :alert="{show: false}"
        :pagination="{ pageSize: 10 }"
        :scroll="{ x: 1200,}"
      >
        <span slot="serial" slot-scope="text, record, index">
          {{ index + 1 }}
        </span>
         <template slot="action" slot-scope="a,b">
          <a @click="openCheck(b)">查看</a>
        </template>
      </s-table>
    </a-card>
    <query-modal
      ref="check"
      :visible="visible"
      @cancel="visible = false"
    />
  </div>
</template>

<script>
import { STable } from '~'
import { mapState } from 'vuex'
import moment from 'moment';
import { DateToString } from '@/utils/common'
import queryModal from './queryModal'


export default {
  data () {
    return {
      advanced: true,
      queryParam: {
        sszym: ''
      },
      visible:false,
      columns: [
        {
          title: '序号',
          width: '80px',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: "学号",
          width: '150px',
          dataIndex: 'xh'
        },
        {
          title: "姓名",
          width: '100px',
          dataIndex: 'xm'
        },
        {
          title: "院系",
          width: '150px',
          dataIndex: 'ssyxmc'
        },
        {
          title: "专业",
          width: '150px',
          dataIndex: 'sszymc'
        },
        {
          title: "论文题目",
          // width: '180px',
          dataIndex: 'lwtm'
        },
        {
          title: '专业领域',
          width: '180px',
          dataIndex: 'zyly'
        },
        {
          title: '授予学位的大学',
          width: '120px',
          dataIndex: 'syxwddx'
        },
        {
          title: '审核状态',
          width: '120px',
          dataIndex: 'shztmc'
        },
        {
          title: "操作",
          width: '80px',
          dataIndex: 'id',
          fixed: 'right',
          scopedSlots: { customRender: 'action' }
        }
      ],
      loadData: parameter => {
        parameter.pageNum = parameter.pageNo
        let params = Object.assign({}, this.queryParam, parameter)
        DateToString(params,'YYYY-MM')
        return this.$api.overseas.paperList(params).then(res => {
          return {
            data: res.data.rows,
            pageNo: parameter.pageNo,
            pageSize: parameter.pageSize,
            totalPage: Math.ceil(res.data.total / parameter.pageSize),
            totalCount: res.data.total
          }
        })
      },
      selectMenu: {}
    }
  },
  components: {STable,queryModal},
  computed: {
    ...mapState({
      TYPE0503: state => state.app['TYPE0503'],
      TYPE0075: state => state.app['TYPE0075']
    })
  },
  created () {
    this.$store.dispatch('app/setDictionary', 'TYPE0075')
    this.$store.dispatch('app/setDictionary', 'TYPE0503')
    this.initSelectMenu()
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yxList: res[0].data
        }
      })
    },
    filterOption (value, op) {
      return op.componentOptions.children[0].text.indexOf(value) !== -1
    },
    yxChange (code) {
      this.$set(this.queryParam, 'zyh', '')
      if (code) {
        this.$api.base.majorAll({lsdwh: code}).then(res => {
          this.$set(this.selectMenu, 'zyList', res.data)
        })
      } else {
        this.$set(this.selectMenu, 'zyList', [])
      }
    },
    exportExcel () {
      let params = {...this.queryParam}
      delete params.pageNum
      this.$export('/xn/bsbylw/exportExcel', params)
    },
    openCheck(info) {
      this.visible = true
      this.$refs.check.info = info
      this.$nextTick(() => {
        this.$refs.check.form.resetFields()
      })
    },
  }
}
</script>

<style>

</style>
